<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href={{url_for('static',filename="css/movie.css")}}>
    <link rel="stylesheet" href={{url_for('static',filename="css/DPlayer.min.css")}}>
    <script src="https://cdn.jsdelivr.net/npm/dplayer@1.25.0/dist/DPlayer.min.js"></script>
    <script src={{url_for('static',filename="js/test.js")}}></script>
    <title>{{info[9]}}</title>
</head>
<body>
    <div id="header">
        {% if 'uid' not in session %}
        <link rel="stylesheet" href={{url_for('static',filename="css/top.css")}}>
        <div id="top">
            <div class="icon"><a href={{url_for('index')}}><strong>Mikufans</strong></a></div>
            <div class="user">
                <a href={{url_for('login')}}>login</a>
            </div>
            <div class="search">
                <form action="search" method="GET"><input type="text" name="keywords" placeholder="233333"><input type="submit" name="submit"></form>
            </div>
        </div>
        {% else %}
        <link rel="stylesheet" href={{url_for('static',filename="css/top_logedin.css")}}>
        <div id="top">
            <div class="icon"><a href={{url_for('index')}}><strong>Mikufans</strong></a></div>
            <div class="user">
                <a href="upload">上传</a>
                <a href="logout">logout</a>
                <a href={{url_for('space',uid=session['uid'])}}>{{session['uname']}}</a>
                <a href={{url_for('space',uid=session['uid'])}} style="margin: 0px;"><img src={{url_for('static',filename="movies/cover/1.jpg")}}></a>
            </div>
            <div class="search">
                <form action="search" method="GET"><input type="text" name="keywords" placeholder="233333"><input type="submit" name="submit"></form>
            </div>
        </div>
        {% endif %}
        <div id="banner"><img src={{url_for('static',filename="banner.jpg")}}></div>
        <div id="index">
            <div class="index"><a href={{url_for('classes',Class="animation")}} target="_blank">动画</a></div>
            <div class="index"><a href={{url_for('classes',Class="music")}} target="_blank">音乐</a></div>
            <div class="index"><a href={{url_for('classes',Class="game")}} target="_blank">游戏</a></div>
            <div class="index"><a href={{url_for('classes',Class="life")}} target="_blank">生活</a></div>
            <div class="index"><a href={{url_for('classes',Class="fashion")}} target="_blank">时尚</a></div>
            <div class="index"><a href={{url_for('classes',Class="kichiku")}} target="_blank">鬼畜</a></div>
            <div class="index"><a href={{url_for('classes',Class="entertain")}} target="_blank">娱乐</a></div>
            <div class="index"><a href={{url_for('classes',Class="dance")}} target="_blank">舞蹈</a></div>
            <div class="index"><a href={{url_for('classes',Class="cinephile")}} target="_blank">影视</a></div>
        </div>
    </div>
    <div id="inner">
        <div id="right">
            <div class="ads">广</div>
            <div class="ads">告</div>
            <div class="ads">位</div>
            <div class="ads">·</div>
            <div class="ads">迫</div>
            <div class="ads">真</div>
        </div>
        <div id="left">
            <div id="movie_{{info[0]}}">
                <div class="title">{{info[9]}}</div>
                <div class="date">
                    <span class="classes">{{info[11]}}</span><span class="date">{{info[10]}}</span>
                </div>
                <div class="info">播放：<span id="play">{{info[4]}}</span> 弹幕：<span id="danmaku">{{info[13]}}</span></div>
                <div id="dplayer"></div>
                <script>
                    
        const dp = new DPlayer({
            container: document.getElementById('dplayer'),
            video: {
                url: '{{url_for('static',filename="movies/movie/{}.mp4".format(info[0]))}}',
                pic: '{{url_for('static',filename="movies/cover/{}.jpg".format(info[0]))}}',
            },
            danmaku: {
                id: 'danmuidformiku{{info[0]}}',
                api: '/danmaku/',
            },
        });

        dp.on("play",function(){
    var xhr
    var formData = new FormData()
    // 实例化一个 XMLHttpRequest 对象
    if (window.XMLHttpRequest) {
      xhr = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE 6及以下
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    // 绑定 xhr.readyState 改变时调用的回调
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                var play=xhr.responseText
                document.getElementById("play").innerHTML=play
                console.log(xhr.responseText)
                console.log('请求成功')
            } else {
            console.log('请求错误')
            }
        }
    }
    formData.append('av',{{info[0]}})
    xhr.open('POST','/update_play');
    // 设置请求头（可选）
    xhr.setRequestHeader('Accept', '*/*')
    // 发出请求
    xhr.send(formData);
});
dp.on("danmaku_send",function(){
    var xhr
    var formData = new FormData()
    // 实例化一个 XMLHttpRequest 对象
    if (window.XMLHttpRequest) {
      xhr = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE 6及以下
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    // 绑定 xhr.readyState 改变时调用的回调
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                var danmaku=xhr.responseText
                document.getElementById("danmaku").innerHTML=danmaku
                console.log(xhr.responseText)
                console.log('请求成功')
            } else {
            console.log('请求错误')
            }
        }
    }
    formData.append('av',{{info[0]}})
    xhr.open('POST','/update_danmaku');
    // 设置请求头（可选）
    xhr.setRequestHeader('Accept', '*/*')
    // 发出请求
    xhr.send(formData);
});

                </script>
                <div>
                    <span onclick="update_like_movie({{info[0]}})">点赞</span><span id="likes_movie">{{info[5]}}</span>
                    <span onclick="update_collection({{info[0]}})">收藏</span><span id="collection">{{info[6]}}</span>
                </div>
                <div class="introduction">简介：{{info[15]}}</div>
                <div class="tags">标签：{{info[16]}}</div>
                {% if 'uid' in session and session['uid']==1 %}
                <a onclick="del({{info[0]}},'sp')">删除</a>
                {% endif %}
            </div>
            {% with messages = get_flashed_messages() %}
            {% if messages %}
            <div>
                {% for message in messages %}
                <p>{{ message }}</p>
                {% endfor %}
            </div>
            {% endif %}
            {% endwith %}
            <div id="comment">
                <div class="send_comment">
                    <form method="POST">
                        <textarea id="send" cols="30" rows="30" name="content" required></textarea>
                        <input type="submit" value="发表评论" name="submit">
                    </form>
                    
                </div>
{% with messages = get_flashed_messages() %}
{% if messages %}
<div>
    {% for message in messages %}
    <p>{{ message }}</p>
    {% endfor %}
</div>
{% endif %}
{% endwith %}
                <div id="comment_list">
                {% if pages==1 %}
                {% for i in comments %}
                    <div class="comment" id="comment_{{i[0]}}">
                        <div class="name">user:{{i[2]}}</div>
                        <div class="content">{{i[3]}}</div>
                        <div class="op">
                            <span>{{i[5]}}</span>
                            <span><span onclick="update_like({{i[0]}})">点赞</span><span id="likes_{{i[0]}}">{{i[4]}}</span></span>
                            <a href="#comment"><span onclick="reply({{i[2]}})">回复</span></a>
                            {% if 'uid' in session and session['uid']==1 %}
                            <a onclick="del({{i[0]}},'pl')">删除</a>
                            {% endif %}
                        </div>
                    </div>
                {% endfor %}
                {% else %}
                {% for i in comments[0:10] %}
                    <div class="comment" id="comment_{{i[0]}}">
                        <div class="name">user:{{i[2]}}</div>
                        <div class="content">{{i[3]}}</div>
                        <div class="op">
                            <span>{{i[5]}}</span>
                            <span><span onclick="update_like({{i[0]}})">点赞</span><span id="likes_{{i[0]}}">{{i[4]}}</span></span>
                            <a href="#comment"><span onclick="reply({{i[2]}})">回复</span></a>
                            {% if 'uid' in session and session['uid']==1 %}
                            <a onclick="del({{i[0]}},'pl')">删除</a>
                            {% endif %}
                        </div>
                    </div>
                {% endfor %}
                {% endif %}
                </div>
                <div class="swap_page">
                    {% for i in range(1,pages+1) %}
                    <a href="#comment"><span onclick="change_page({{i}},{{info[0]}})">{{i}}</span></a>
                    {% endfor %}
                </div>
            </div>
        </div>
    </div>
    <div id="footer">footer</div>


</body>
</html>